wsbp_chart_library = {
	isStockChart : false,
	isColumnChart : true,
	columnSeries : 1,
	activeSeries : 1,
	
	stockChart : {
		flashChart : null,
		swfObject : null,
		
		chartWidth : 946,
		chartHeight : 300,
		chartDiv : "placeholder",
		chartObjID : "chart1",
		flashVersion : "8",
		backgroundColor : "#FFFFFF",
		preloaderColor : "#999999",
		wmode : "opaque",
		currSeries : 0,
		
		chartConf : null,
		
		init : function() {
			this.swfObject = new SWFObject(base_url + "js/amcharts/amstock/amstock.swf", this.chartObjID, this.chartWidth, this.chartHeight, this.flashVersion, this.backgroundColor);
			
			this.swfObject.addVariable("chart_id", this.chartObjID);
			this.swfObject.addVariable("path", base_url + "js/amcharts/amstock/");
			this.swfObject.addVariable("preloader_color", this.preloaderColor);
			this.swfObject.addVariable("settings_file", "");
	  		this.swfObject.addVariable("chart_settings", encodeURIComponent(this.chartConf));
	  		this.swfObject.addVariable("key", "107-cceff84f2f0cededc8c9a2952fabde7b");
	 		this.swfObject.addParam('wmode', this.wmode);
			
			this.swfObject.write(this.chartDiv);
		},
		
		printChart : function () {
			if(this.flashChart != null) {
				this.flashChart.print();
			}
		},
		
		exportImageChart : function () {
			if(this.flashChart != null) {
				this.flashChart.exportImage(base_url + "js/amcharts/amstock/export.php");
			}
		},
		
		activateSeries : function (seriesID) {
			if(this.flashChart != null) {
				this.currSeries = seriesID;
				this.flashChart.selectDataSet(seriesID);
			}
		},
		
		popUpAdjustScale : function (seriesID) {
			apprise(dataRangeQuestion, {'input1': dataRangeMin, 'input2': dataRangeMax, 'confirm':true, 'textCancel': dataRangeCancel}, function(r, i1, i2) {
				if(r) {
					if((i1 == 'max' || i1 == 'min' || i1 == parseFloat(i1)) && (i2 == 'max' || i2 == 'min' || i2 == parseFloat(i2))) {
						if(wsbp_chart_library.stockChart.flashChart != null) {
							dataRangeMin = i1;
							dataRangeMax = i2;
							wsbp_chart_library.stockChart.flashChart.setSettings("<settings><charts><chart cid=\"0\"><values><y_right><min>" + dataRangeMin + "</min><max>" + dataRangeMax + "</max></values></y_right></chart></charts></settings>");
						}
					} else {
						alert("Invalid scale");
					}
				}
			});
		}
	},
	columnChart : {
		flashChart : null,
		swfObject : null,
		
		chartWidth : 946,
		chartHeight : 300,
		chartDiv : "placeholder",
		chartObjID : "chart1",
		flashVersion : "8",
		backgroundColor : "#FFFFFF",
		preloaderColor : "#999999",
		wmode : "transparent",
		
		chartConf : null,
		
		init : function() {
			this.swfObject = new SWFObject(base_url + "js/amcharts/bundle/flash/amcolumn.swf", this.chartObjID, this.chartWidth, this.chartHeight, this.flashVersion, this.backgroundColor);
			
			this.swfObject.addVariable("path", base_url + "/js/bundle/flash/");
			this.swfObject.addVariable("preloader_color", this.preloaderColor);
			this.swfObject.addVariable("settings_file", "");
	  		this.swfObject.addVariable("chart_settings", encodeURIComponent(this.chartConf));
	 		this.swfObject.addVariable("chart_id", this.chartObjID);
	 		this.swfObject.addParam('wmode', this.wmode);
			
			this.swfObject.write(this.chartDiv);
		},
		
		printChart : function () {
			if(this.flashChart != null) {
				this.flashChart.print();
			}
		},
		
		exportImageChart : function () {
			if(this.flashChart != null) {
				this.flashChart.exportImage(base_url + "js/amcharts/bundle/flash/export.php");
			}
		}
	},
	pieChart : {
		flashChart : null,
		swfObject : null,
		
		chartWidth : 946,
		chartHeight : 300,
		chartDiv : "placeholder",
		chartObjID : "chart3",
		flashVersion : "8",
		backgroundColor : "#FFFFFF",
		preloaderColor : "#999999",
		wmode : "transparent",
		
		chartConf : null,
		
		init : function() {
			this.swfObject = new SWFObject(base_url + "js/amcharts/bundle/flash/ampie.swf", this.chartObjID, this.chartWidth, this.chartHeight, this.flashVersion, this.backgroundColor);
			
			this.swfObject.addVariable("path", base_url + "/js/bundle/flash/");
			this.swfObject.addVariable("preloader_color", this.preloaderColor);
			this.swfObject.addVariable("settings_file", "");
	  		this.swfObject.addVariable("chart_settings", encodeURIComponent(this.chartConf));
	 		this.swfObject.addVariable("chart_id", this.chartObjID);
	 		this.swfObject.addParam('wmode', this.wmode);
			
			this.swfObject.write(this.chartDiv);
		},
		
		printChart : function () {
			if(this.flashChart != null) {
				this.flashChart.print();
			}
		},
		
		exportImageChart : function () {
			if(this.flashChart != null) {
				this.flashChart.exportImage(base_url + "js/amcharts/bundle/flash/export.php");
			}
		}
	},
	
	activateSeries : function (seriesID) {
		if(this.isStockChart) {
			if(seriesID == this.columnSeries) {
				this.hideStockChart();
				this.showColumnChart();
			} else if(seriesID != this.activeSeries){
				this.stockChart.flashChart.selectDataSet(seriesID);
			}
		} else {
			if(seriesID != this.columnSeries) {
				this.hideColumnChart();
				this.showStockChart();
				this.stockChart.flashChart.selectDataSet(seriesID);
			}
		}
	},
	
	hideStockChart : function () {
		$("#" + this.stockChart.chartDiv).height(0);
		$("#" + this.stockChart.chartDiv).css('visibility', 'hidden');
		this.isStockChart = false;
	},
	
	showStockChart : function () {
		$("#" + this.stockChart.chartDiv).height(this.stockChart.chartHeight);
		$("#" + this.stockChart.chartDiv).css('visibility', 'visible');
		this.isStockChart = true;
	},
	
	hideColumnChart : function () {
		$("#" + this.columnChart.chartDiv).height(0);
		$("#" + this.columnChart.chartDiv).css('visibility', 'hidden');
		this.isColumnChart = false;
	},
	
	showColumnChart : function () {
		$("#" + this.columnChart.chartDiv).height(this.columnChart.chartHeight);
		$("#" + this.columnChart.chartDiv).css('visibility', 'visible');
		this.isColumnChart = true;
	}
}